// pages/sfc/sfc.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //日期选择器：
    date: '选择发车日期', 
    
    //顺风车列表：
    currentTab: 0,
    //查询数据
    searchData:'',
    shuju:''
  },

  //日期选择器：
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  fromSub(e){
    var that = this
    if(e.detail.value.start == ''){
      wx.showToast({
        title: '请设置出发地',
        icon:'none'
      })
    }else if(e.detail.value.goal == ''){
      wx.showToast({
        title: '请设置目的地',
        icon:'none'
      })
    }else if(e.detail.value.time == '' || e.detail.value.time == '选择发车日期'){
      wx.showToast({
        title: '请选择发车日期',
        icon:'none'
      })
    }else{
      wx.showLoading({
        title: '搜索中',
      })
      that.setData({
        shuju:e.detail.value
      })
      var type = ''
      // this.getquan()
    }
  },
  search(data,type){
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    data.area = wx.getStorageSync('caty').name
    data.type = type
    app.wxRequest('post','/Samecity/Freeride/Freeridelist',data,(res)=>{
      console.log(res)
      wx.hideLoading()
      if(res.data.code == 0){
        wx.showToast({
          list: res.data.msg,
          icon:'none'
        })
      }else{
        that.setData({
          searchData:res.data
        })
      }
    },(err)=>{
      console.log(err)
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  //滑动切换
  swiperTab: function (e) {
    var that = this;
    that.setData({
      currentTba: e.detail.current
    });
  },
  //点击切换
  clickTab: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
      var type = ''
      if(e.target.dataset.current == 1){
        this.setData({
          type:2
        })
        
      }else if(e.target.dataset.current == 2){
       
        this.setData({
          type:1
        })
      }
      that.getquan()
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
      this.getquan();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  
  /*返回上一页*/
  navigateBack: function () {
    var self = this;
    var pages = getCurrentPages();
    if (pages.length == 1) {
      if (self.data.circleId && self.data.circleId > 0) {
        wx.redirectTo({
          url: '../../circle/index/index?circleId=' + self.data.circleId
            + '&circleName=' + (self.data.circleName || '')
        });
      } else {
        wx.switchTab({
          url: "../../home/grouplist/grouplist"
        });
      }
    } else {
      wx.navigateBack({ changed: true });//返回上一页  
    }
  },

  /*拨号*/
  calling: function () {
    wx.showActionSheet({
      itemList: ['400-900-2250'],
      success: function (res) {
        console.log(res) //当点击400-900-2250就相当于点击了
        wx.makePhoneCall({
          phoneNumber: '400-900-2250', //此号码并非真实电话号码，仅用于测试  
          success: function () {
            console.log("拨打电话成功！")
          },
          fail: function () {
            console.log("拨打电话失败！")
          }
        })
        if (!res.cancel) {
          console.log(res.tapIndex)//console出了下标
        }
      }
    });
  },
  
  //全部
  getquan:function(){
    let _this=this
    var city = wx.getStorageSync("city")
    var type = _this.data.type
    app.wxRequest('get','/Samecity/Freeride/Freeridelist', {city:city,type:type}, function (res) {
      console.log(res)
      _this.setData({
        list: res.data.data,
      })
    }, function (err) {
      wx.showToast({
        title: err.data.msg,
        icon: 'none'
      })
    })
  }


})